package first;

import java.io.*;
import java.net.*;

public class Server {
	private Socket s ;
	private ServerSocket ss;
	int port = 9001;
	Server(){
		try {
			while(true){
				ss = new ServerSocket(9000);
				s = ss.accept();
				waitfor();
				ss.close();
				s.close();
				ServerSocket sss = new ServerSocket(port);
				Socket socket = sss.accept();
				System.out.println("ok");
			}
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		System.out.println("ok");
		waitfor();
		newConnection();
	}
	private void newConnection(){
		
	}
	private void waitfor(){
		try {
			DataOutputStream out = new DataOutputStream(s.getOutputStream());
			out.writeDouble(port);
//			System.out.println("9001");
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		new Server();
	}

}
class serverThread extends Thread{
	
}